package com.tea.funct.controller;

import com.tea.common.annotation.Log;
import com.tea.common.core.controller.BaseController;
import com.tea.common.core.domain.AjaxResult;
import com.tea.common.core.page.TableDataInfo;
import com.tea.common.enums.BusinessType;
import com.tea.common.utils.poi.ExcelUtil;
import com.tea.funct.domain.TeaCategory;
import com.tea.funct.service.ITeaCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品大类Controller
 *
 * @author Sophia
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/funct/category")
public class TeaCategoryController extends BaseController {
    @Autowired
    private ITeaCategoryService teaCategoryService;

    /**
     * 查询产品大类列表
     */
    @PreAuthorize("@ss.hasPermi('funct:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaCategory teaCategory) {
        startPage();
        List<TeaCategory> list = teaCategoryService.selectTeaCategoryList(teaCategory);
        return getDataTable(list);
    }

    /**
     * 查询产品大类列表
     */
    @PreAuthorize("@ss.hasPermi('funct:category:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll() {
        List<TeaCategory> list = teaCategoryService.selectTeaCategoryListAll();
        return getDataTable(list);
    }

    /**
     * 导出产品大类列表
     */
    @PreAuthorize("@ss.hasPermi('funct:category:export')")
    @Log(title = "产品大类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaCategory teaCategory) {
        List<TeaCategory> list = teaCategoryService.selectTeaCategoryList(teaCategory);
        ExcelUtil<TeaCategory> util = new ExcelUtil<TeaCategory>(TeaCategory.class);
        util.exportExcel(response, list, "产品大类数据");
    }

    /**
     * 获取产品大类详细信息
     */
    @PreAuthorize("@ss.hasPermi('funct:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(teaCategoryService.selectTeaCategoryById(id));
    }

    /**
     * 新增产品大类
     */
    @PreAuthorize("@ss.hasPermi('funct:category:add')")
    @Log(title = "产品大类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaCategory teaCategory) {
        return toAjax(teaCategoryService.insertTeaCategory(teaCategory));
    }

    /**
     * 修改产品大类
     */
    @PreAuthorize("@ss.hasPermi('funct:category:edit')")
    @Log(title = "产品大类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaCategory teaCategory) {
        return toAjax(teaCategoryService.updateTeaCategory(teaCategory));
    }

    /**
     * 删除产品大类
     */
    @PreAuthorize("@ss.hasPermi('funct:category:remove')")
    @Log(title = "产品大类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(teaCategoryService.deleteTeaCategoryByIds(ids));
    }
}
